
-- models_t = {}
-- function getModels( handler, id, encoded, decoded)
	-- models_t = decoded 
-- end
-- datastream.Hook("sendProps", getModels)

pnl = {}
function modelPanel()
	if pnl != nil then pnl:Remove() end
	local mdl = models_t[1].mdl
	pnl = vgui.Create("DModelPanel")
	pnl:SetPos(ScrW()/2 - 24 - 96, ScrH()-72)
	pnl:SetSize(48,48)	
	pnl:SetCamPos(Vector( 40, 40, 60 ))
	pnl:SetLookAt(Vector(0,0,0))
	pnl:SetModel(mdl)
end
usermessage.Hook("show_model_panel", modelPanel)


function hideModelPanel()
	pnl:Remove()
end
usermessage.Hook("hide_model_panel", hideModelPanel)


tab = nil
function tabMenu()
	if tab == nil then 
		tab = vgui.Create( "DFrame" )
		local w, h = 800, 800
		tab:SetPos( (ScrW()/2) - w / 2,(ScrH()/2) - h / 2 )
		tab:SetSize( w, h )
		tab:SetTitle( "" )
		tab:SetVisible( true )
		tab:SetDraggable( false )
		tab:ShowCloseButton( false )
		tab:MakePopup()
		function tab:Paint()
			local tb_w,tb_h = 700, 700
			--surface.CreateFont ("Arial", 28, 400, true, false, "CV20")
			surface.SetFont( "DefaultBold" )

			surface.SetDrawColor(50,50,50,125) -- gray drawing color
			surface.DrawRect(20, 20 ,tb_w , tb_h) 
			
			local y = 0
			draw.SimpleText("Red Team", "DefaultBold",20,20,team.GetColor(1))
			for k,v in pairs(team.GetPlayers(1)) do
				y = y + 20
				draw.SimpleText(v:Nick(), "DefaultBold",40,20 + y,team.GetColor(v:Team()))
				draw.SimpleText(v:Frags().."", "DefaultBold",240,20 + y,team.GetColor(v:Team()))
				draw.SimpleText(v:Deaths().."", "DefaultBold",280,20 + y,team.GetColor(v:Team()))
			end	
			
			local y2 = 0
			local offset = 380
			draw.SimpleText("Blue Team", "DefaultBold",380,20,team.GetColor(2))
			for k,v in pairs(team.GetPlayers(2)) do
				y2 = y2 + 20
				draw.SimpleText(v:Nick(), "DefaultBold",40+offset,20 + y2,team.GetColor(v:Team()))
				draw.SimpleText(v:Frags().."", "DefaultBold",240+offset,20 + y2,team.GetColor(v:Team()))
				draw.SimpleText(v:Deaths().."", "DefaultBold",280+offset,20 + y2,team.GetColor(v:Team()))
			end
			
			local y3 = 0
			draw.SimpleText("Spectator", "DefaultBold",40,600,team.GetColor(3))
			for k,v in pairs(team.GetPlayers(3)) do
				y3 = y3 + 20
				draw.SimpleText(v:Nick(), "DefaultBold",40,620 + y3 ,team.GetColor(v:Team()))
				draw.SimpleText(v:Frags().."", "DefaultBold",40,620 + y3,team.GetColor(v:Team()))
				draw.SimpleText(v:Deaths().."", "DefaultBold",40,620 + y3,team.GetColor(v:Team()))
			end
		end		 
	
	else
		tab:Close()
		tab = nil
	end
end

function scrollUp()
	RunConsoleCommand("pf_scroll_up")
end

function updateModel(um)
	local ind = um:ReadShort()
	if(models_t[ind] != nil) then
		pnl:SetModel(models_t[ind].mdl)
	end
end
usermessage.Hook("change_panel_model", updateModel)

function scrollDown()
	RunConsoleCommand("pf_scroll_down")
end

function scroll(ply, bind, pressed)
	if(bind == "invprev") then
		scrollUp()
		return true
	elseif(bind == "invnext") then
		scrollDown()
		return true
	elseif(bind == "+showscores") then
		tabMenu()
		return true
	end	
end
hook.Add("PlayerBindPress", "scrollcheck", scroll)